<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*
        先请求A 再请求B 再请求C
        */

        async function getData(){
            const user = await new Promise((resolve,reject)=>{
                console.log("A数据开始请求...");
                try{
                    throw new Error("err")
                    setTimeout(()=>{
                      console.log("A数据请求成功"); 
                      const user= {
                        userName: "张三"
                      } 
                      resolve(user)
                    },2000)
                }catch(e){
                    reject(e.message)
                }
            })

            const sex = await new Promise((resolve,reject)=>{
                console.log("B数据开始请求...");
                try{
                    setTimeout(()=>{
                      console.log("B数据请求成功"); 
                      const sex= {
                        sex: "男"
                      } 
                      resolve({
                        ...user,
                        ...sex
                      })
                    },2000)
                }catch(e){
                    reject(e.message)
                }
            })

            const age = await new Promise((resolve,reject)=>{
                console.log("C数据开始请求...");
                try{
                    setTimeout(()=>{
                      console.log("C数据请求成功"); 
                      const age= {
                        age: 18
                      } 
                      resolve({
                        ...sex,
                        ...age
                      })
                    },2000)
                }catch(e){
                    reject(e.message)
                }
            })

            console.log("完整的数据是",age);
        }

        getData()
    </script>
</body>
</html>